using Microsoft.EntityFrameworkCore;
using Wordss.Models;
namespace Wordss.Dto;

public class Dtoj<T> : IDtojs<T> where T :class{
    public readonly Wode _db;
    public readonly DbSet<T> _tb;

    public Dtoj(Wode db){
        _db=db;
        _tb=db.Set<T>();
    }
    public    async Task<List<T>> GetAll(){
        var List =await _db.Set<T>().ToListAsync();
        return List;
    }
    public    async Task<T?> GetByAll(Guid id){
        return await _tb.FindAsync(id); 
    }
    public    async Task<T> PastAsync(T entity){
        var obj =_db.Set<T>().Add(entity).Entity;
        await _db.SaveChangesAsync();
        return obj;
    }
     public    async Task PutAsync (T entity){
        _tb.Update(entity);
        await _db.SaveChangesAsync();
     }
     public   async Task DelAsync (T entity){
        _tb.Remove(entity);
        await _db.SaveChangesAsync();
     }
} 